<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>

<%@ page import="java.util.Map" %>
<%@ page import="com.broadvision.data.common.PrimitiveType" %>

<c:set var="formBean" value="${emSimpleConditionEditForm}" />
<c:set var="formBeanMap" value="${formBean.map}" />

<c:set var="viewBean" value="${emEnumConditionEditView}" />
<c:set var="viewBeanMap" value="${viewBean.map}" />


<SCRIPT language='Javascript'>
  function cancelAction(theForm){
	window.location="<html-el:rewrite page="/em/cb/displayCriteriaBuilder.do"/>";
    return false;
  }

  <c:if test="${formBeanMap.fromBranchNew && not empty formBeanMap.backURL}"> 
    function backToURLPage(theForm) {
      theForm.action = "<c:out value="${formBeanMap.backURL}" />";
      //We don't need validate data here since they will not be used.
      theForm.submit();
      return false;
    }
  </c:if>
  function saveCondition(theForm) {
    <c:choose>
      <c:when test="${formBeanMap.fromBranchNew && not empty formBeanMap.backURL}" >
        theForm.action = "<html-el:rewrite page="/em/cb/profMvBranchConditionUpdate.do" />";
      </c:when>
      <c:otherwise>
        theForm.action = "<html-el:rewrite page="/em/cb/profSimpleConditionUpdate.do" />";
      </c:otherwise>
    </c:choose>
    theForm.submit();
    return false;
  }

  
  <%
    final String typeStr ="enum";
    pageContext.setAttribute("typeStr", typeStr);
  %>
  
  
</script>

<html-el:form action="/em/cb/profSimpleConditionUpdate.do"> 
  <html-el:errors/>
  <html-el:hidden property="actType" />
  <html-el:hidden property="key" />
  <html-el:hidden property="fromBranchNew" />
  <html-el:hidden property="backURL" />
  
  <c:set var="pageTitle">
    <c:choose>
      <c:when test='${formBeanMap.actType == "create"}'>
        <bean-el:message bundle="em" key="em.cb.condition.add" />
      </c:when>
      <c:otherwise>
        <bean-el:message bundle="em" key="em.cb.condition.edit" />
      </c:otherwise>
    </c:choose>
  </c:set>
  
  
 <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle"><c:out value="${pageTitle}" /></div>
      <div class="errorMessage"><html-el:errors/></div>

      <!--end page title area here-->
      
      <div class="pageSubtitle">
        <span class="left"><c:out value="${pageTitle}" /></span>
        <span class="right">&nbsp;</span>
      </div>
      <div class="pageInstructions">
        <c:choose>
          <c:when test="${formBeanMap.fromBranchNew}"> 
            <bean-el:message bundle="em" key="em.cb.relational.condition.instruction.complex"/>
          </c:when>
          <c:otherwise>
            <bean-el:message bundle="em" key="em.cb.relational.condition.instruction.simple"/>
          </c:otherwise>
        </c:choose>
      </div>

   <!--start main content here-->
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="labelField">
          <c:set var="operatorList">
            <html-el:select property="operator" size="1">
              <html-el:optionsCollection name="viewBean" property="operatorList" /> 
              </html-el:select>
          </c:set>
          <c:set var="attributeList">
            <html-el:select property="itemValue" size="1">
            <html-el:optionsCollection name="viewBean" property="attributeList" /> 
            </html-el:select>
          </c:set>

    <%
      String operatorList = (String)pageContext.getAttribute("operatorList"); 
      String attributeList = (String)pageContext.getAttribute("attributeList"); 
      String friendlyAttributeName = (String)((Map)pageContext.getAttribute("viewBeanMap")).get("friendlyAttributeName");
    %>
          <bean-el:message bundle="em" key="em.cb.relationalCondition.whole.sentence" 
         arg0="<%=friendlyAttributeName%>" arg1="<%=operatorList%>" arg2="<%=attributeList%>" /> 
        </td>
      </tr>
    </table>
      
    <div class="pageButtonWrap" align="right">
        <c:if test="${formBeanMap.fromBranchNew && not empty formBeanMap.backURL}" >
          <input type="button" name="backBtn" value="<bean-el:message bundle="em" key="button.previous" />" class="inputButton" onclick="javascript:return backToURLPage(this.form)" >
        </c:if>
        <input type="button" name="cancelBtn" value="<bean-el:message bundle="em" key="button.cancel"/>" class="inputButton" onclick="javascript:return cancelAction()">
        <input type="button" name="saveBtn" value="<bean-el:message bundle="em" key="button.done"/>" class="inputButton" onclick="javascript:return saveCondition(this.form)">
    </div>
    </td>
  </tr>
</table>
</html-el:form>